﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace yq.WebModel
{
    public class ListPage<T>  where T : yq.IBase.IModelBase, new()
    {
        
        private string _FormId = string.Empty;
       
        public string FormId
        {
            get { if (_FormId == string.Empty) { _FormId = "form0"; } return _FormId; }
            set { _FormId = value; }
        }

        /// <summary>
        /// 当前列表需要的PagerList对象
        /// </summary>
        private yq.Dictionary.PageList<T> _PageList = null;
        /// <summary>
        /// 当前列表需要的PagerList对象
        /// </summary>
        public yq.Dictionary.PageList<T> PageList
        {
            get { if (_PageList == null) { _PageList = new yq.Dictionary.PageList<T>(); } return _PageList; }
            set { _PageList = value; }
        }

        /// <summary>
        /// 写入PageList，写入类可以是T的子类
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <param name="list"></param>
        public void SetPageList<K>(yq.Dictionary.PageList<K> list)
        {
            foreach (var info in list)
            {
                var model = new T();
                model.SetValue(info);
                PageList.Add(model);
            }

            PageList.PagerModel =  list.PagerModel ?? new yq.Dictionary.PageModel() ;
        }

        /// <summary>
        /// 写入IList，写入类可以是T的子类
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <param name="list"></param>
        public void SetList<K>(IList<K> list)
        {
            foreach (var info in list)
            {
                var model = new T();
                model.SetValue(info);
                List.Add(model);
            }
        }

        /// <summary>
        /// 无分页列表LIST对象
        /// </summary>
        private IList<T> _List = null;

        /// <summary>
        /// 无分页列表LIST对象
        /// </summary>
        public IList<T> List
        {
            get { if (_List == null) { _List = new List<T>(); } return _List; }
            set { _List = value; }
        }

        private Dictionary<string, RoleLinkButton> _RoleLinkList =new Dictionary<string, RoleLinkButton>();

        /// <summary>
        /// 权限控件列表
        /// </summary>
        public Dictionary<string,RoleLinkButton> RoleLinkList
        {
            get { return _RoleLinkList; }
            set { _RoleLinkList = value; }
        }
       
       /// <summary>
       /// 添加权限判断控件
       /// </summary>
       /// <param name="_LinkText"></param>
       /// <param name="_ActionName"></param>
       /// <param name="_ControllerName"></param>
       /// <param name="_AreaName"></param>
       public void  AddRoleLinkButton(string _LinkText, string _ActionName, string _ControllerName, string _AreaName = null)
       {
             _RoleLinkList.Add(_LinkText,new RoleLinkButton(_LinkText, _ActionName, _ControllerName, _AreaName));
       }
    }

    /// <summary>
    /// 权限按钮
    /// </summary>
    public class RoleLinkButton
    {
        /// <summary>
        /// 添加要跳转的方法
        /// </summary>
        /// <param name="_LinkText"></param>
        /// <param name="_ActionName"></param>
        /// <param name="_ControllerName"></param>
        /// <param name="_AreaName"></param>
        public RoleLinkButton(string _LinkText, string _ActionName, string _ControllerName, string _AreaName = null)
        {
            ActionName = _ActionName;
            ControllerName = _ControllerName;
            AreaName = _AreaName;
            LinkText = _LinkText;
        }

        string _LinkText;

        public string LinkText
        {
            get { return _LinkText; }
            set { _LinkText = value; }
        }



        string _ActionName;

        public string ActionName
        {
            get { return _ActionName; }
            set { _ActionName = value; }
        }


        string _ControllerName;

        public string ControllerName
        {
            get { return _ControllerName; }
            set { _ControllerName = value; }
        }


        string _AreaName = null;

        public string AreaName
        {
            get { return _AreaName; }
            set { _AreaName = value; }
        }


        yq.Enums.BooleanType _IsShowButton = yq.Enums.BooleanType.UnKnow;
        /// <summary>
        /// 是否通过判断
        /// </summary>
        public yq.Enums.BooleanType IsShowButton
        {
            get { return _IsShowButton; }
            set { _IsShowButton = value; }
        }
    }
}
